<?php

/**
 * @version     $Id: invalidkeylog.php 3 2010-10-08 17:49:35Z obalyuk87@gmail.com $
 * @package     AdminSafe
 * @subpackage  Components
 * @copyright   Copyright (C) 2010 Oleksandr Balyuk (www.boolcast.com)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL v2
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
// No direct access
defined('_JEXEC') or die('Restricted access');

/**
 *
 * @author Oleksandr Balyuk <obalyuk@boolcast.com>
 */
class TableInvalidKeyLog extends JTable {

    public $id = null;
    public $ip_address = null;
    public $date_time = null;
    public $os = null;
    public $browser = null;
    public $key = null;
    //
    private $_componentPath = null;

    /**
     * Default Constructor
     *
     * @param JDatabase Database connector object
     */
    public function __construct(&$db) {
        parent::__construct('#__adminsafe_invalidkeylog', 'id', $db);

        //
        $this->_componentPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_adminsafe';
    }

    /**
     * Checks table values
     * 
     * @return bool
     */
    public function check() {
        //
        if (!$this->date_time) {
            $this->date_time = JFactory::getDate(time())->toMySQL();
        }

        //
        if (!$this->ip_address) {
            $this->ip_address = $_SERVER['REMOTE_ADDR'];
        }

        //
        if (!$this->os) {
            require_once $this->_componentPath . DS . 'helpers' . DS . 'AdminsafeUserDetector.php';
            $this->os = AdminsafeUserDetector::getOs();
        }

        //
        if (!$this->browser) {
            require_once $this->_componentPath . DS . 'helpers' . DS . 'AdminsafeUserDetector.php';
            $this->browser = AdminsafeUserDetector::getBrowser();
        }

        //
        if (!$this->key) {
            $thsi->key = '';
        }

        return true;
    }

}